import Vue from 'vue'
import VueRouter from 'vue-router'
import Home from '../views/Home/index.vue'//根页面
import Login from '../views/Login/index.vue'//登录页面
// import Find from '../views/Find/index.vue' //未知错误路由
// import Page from './errPage'//404,500
import Page404 from '../views/ErrPage/404.vue';
import mainPage from "./mainPage";//home下的二级子路由--main/my/newhome/oldhome/renthome
import Position from '../views/Position/index.vue'//定位页面--上海
import Houselist from '../views/Houselist/index.vue' //  列表（新房/二手房/商铺）页面
import Maphouse from '../views/Maphouse/index.vue';//地图找房页面
import Details from '../views/Details/index.vue';//详情页面
import Dpage from '../views/Dpage/index.vue';
import Second from '../views/Second/index.vue';
import Publish from '../views/Publish/index.vue';
import Question from '../views/Question/index.vue';
Vue.use(VueRouter)

const routes = [
  // ...Page,
  {
    //首页
    path: "/",
    component: Home,
    redirect: '/main',
    children: [
      ...mainPage
    ]
  },
  {
    //登录页面
    path: "/login",
    component: Login
  },
  {
    //  列表（新房/二手房/商铺）页面
    path: "/houselist",
    component: Houselist
  },
  {
    //当路由配置表中没有与跳转路径对应的路由时，统一会走到path:*这个页面去
    path: "*",
    component: Page404
  },
  // {
  //   //未知错误路由
  //   path: "find",
  //   component: Find
  // },
  {
    //定位页面--上海
    path: "/position",
    component: Position
  },
  {
    //地图找房页面
    path: "/maphouse",
    component: Maphouse
  },
  {
    //详情页面
    name: 'detail',
    path: "/detail/:id",
    component: Details
  },
  {
    path: "/second",
    component: Second
  },
  {
    path: "/publish",
    component: Publish
  },
  {
    path: "/dpage",
    component: Dpage
  },
  {
    path: "/question",
    component: Question
  }
]
const router = new VueRouter({
  mode: 'history',
  base: process.env.BASE_URL,
  routes
})
//导航守卫
// router.beforeEach((to, from, next) => {
//   console.log(to)
//   const token = localStorage.getItem("token");
//   if (!token && to.path !== '/login' && !to.meta.filter) {
//     next("/login")
//   } else {
//     next()
//   }
// })
// router.beforeEach((to, from, next) => {
//   const token = localStorage.getItem("token");
//   if (!token) {
//     // next("login")
//     next();
//   } else {
//     next("/login")
//     // next()
//   }
// })
export default router
